//index.js
//获取应用实例
const app = getApp()
import { ActivityMixinsHaveTabbar, PageListMixins } from '../../behaviors/page'
import { USER_EXT_INFO_SCENE, USER_ACTION_TYPE } from '../../constants/user';
import { getUserExtInfo, getIndexRecentActivity } from '../../api/usr';
const { showLoading, hideLoading } = require('../../common/env')

Page({
    mixins: [ActivityMixinsHaveTabbar, PageListMixins],
    data: {
        userExtInfo: {},
        activityList: [],
    },
    // onLoad: function () {
    //     // 打开调试
    //     wx.setEnableDebug({
    //         enableDebug: true
    //     })
    // },
    onShow: async function () {
        const that = this;
        if (!app.globalData.isReadyAuth) {
            // app.userIdentifyCallback = this.onLoad;
            const originFunc = app.userIdentifyCallback;
            app.userIdentifyCallback = function (...args) {
                that.onShow(...args);
                return originFunc && originFunc(...args);
            }
            return;
        } else {
            // 获取用户额外信息
            const userExtInfo = await getUserExtInfo(USER_EXT_INFO_SCENE.index);
            this.setData({
                userExtInfo,
            });
        }
    },
    // 获取活动列表
    getListData: async function (isReplace=false) {
        showLoading('加载活动...');
        const { pageNo, pageSize, pageTime, activityList } = this.data;
        const list = await getIndexRecentActivity({
            pageNo,
            pageSize,
            ts: pageTime,
        });
        const userExtInfo = await getUserExtInfo(USER_EXT_INFO_SCENE.index);
        this.setData({
            activityList: isReplace ? list : [...activityList, ...list],
            userExtInfo,
        });
        hideLoading();
    },
})